package com.droid.lib.controls.demo.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.MultiAutoCompleteTextView;

//import com.android.ex.chips.BaseRecipientAdapter;
//import com.android.ex.chips.RecipientEditTextView;
//import com.android.ex.chips.recipientchip.DrawableRecipientChip;
import com.android.ex.chips.BaseRecipientAdapter;
import com.android.ex.chips.RecipientEditTextView;
import com.android.ex.chips.recipientchip.DrawableRecipientChip;
import com.droid.lib.controls.demo.R;
import com.droid.lib.controls.widget.RippleView;
import com.droid.lib.controls.demo.widget.cards.ui.NativeMenuActivity;

/**
 * 卡片，贴片
 * Created by Administrator on 2016/9/20.
 */
public class CardsFragment extends Fragment {
    private Context mContext;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContext = getActivity();
       View view=LayoutInflater.from(mContext).inflate(R.layout.fragment_cards,null);
        RippleView mrvCardsLib=(RippleView)view.findViewById(R.id.rv_cards_lib);
        mrvCardsLib.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(),NativeMenuActivity.class);
                getActivity().startActivity(intent);
            }
        });
        final RecipientEditTextView phoneRetv =
                (RecipientEditTextView) view.findViewById(R.id.phone_retv);
        phoneRetv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
        BaseRecipientAdapter adapter = new BaseRecipientAdapter(BaseRecipientAdapter.QUERY_TYPE_PHONE, mContext);
        adapter.setShowMobileOnly(true);
        phoneRetv.setAdapter(adapter);
        phoneRetv.dismissDropDownOnItemSelected(true);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                DrawableRecipientChip[] chips = phoneRetv.getSortedRecipients();
                for (DrawableRecipientChip chip : chips) {
                    Log.v("DrawableChip", chip.getEntry().getDisplayName() + " " + chip.getEntry().getDestination());
                }
            }
        }, 5000);

        final ImageButton showAll = (ImageButton) view.findViewById(R.id.show_all);
        showAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                phoneRetv.showAllContacts();
            }
        });
        return view;

    }
}
